package cn.nfwx.tv.fragment.me;

import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.Context;
import android.graphics.Color;
import android.graphics.Typeface;
import android.text.Spannable;
import android.text.Spanned;
import android.text.style.ForegroundColorSpan;
import android.text.style.RelativeSizeSpan;
import android.text.style.StyleSpan;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;

import cn.nfwx.tv.R;
import cn.nfwx.tv.base.BaseFragment;
import cn.nfwx.tv.util.ToastUtil;

public class AboutFragment extends BaseFragment {
    @Override
    public View initView() {
        return LayoutInflater.from(getContext()).inflate(R.layout.fragment_about, null);
    }

    @Override
    public void initData() {
        super.initData();
        Spannable spannable = Spannable.Factory.getInstance().newSpannable(getString(R.string.about_wx_text2));
        ForegroundColorSpan backgroundColorSpan = new ForegroundColorSpan(Color.BLACK);
        RelativeSizeSpan relativeSizeSpan = new RelativeSizeSpan(1.2f);
        StyleSpan styleSpan_Bold = new StyleSpan(Typeface.BOLD);
        spannable.setSpan(styleSpan_Bold, 12, 20, Spanned.SPAN_INCLUSIVE_INCLUSIVE);
        spannable.setSpan(backgroundColorSpan, 12, 20, Spanned.SPAN_INCLUSIVE_INCLUSIVE);
        spannable.setSpan(relativeSizeSpan, 12, 20, Spanned.SPAN_INCLUSIVE_INCLUSIVE);
        ((TextView) findView(getView(), R.id.tv_about_2)).setText(spannable);

        final TextView textView = findView(getView(), R.id.tv_about_1);
        textView.setOnLongClickListener(new View.OnLongClickListener() {
            @Override
            public boolean onLongClick(View v) {
                ClipboardManager cmb = (ClipboardManager) getActivity().getSystemService(Context.CLIPBOARD_SERVICE);
                if (cmb != null) {
                    cmb.setPrimaryClip(ClipData.newPlainText(null, textView.getText().toString().trim()));  //将内容放入粘贴管理器,在别的地方长按选择"粘贴"即可
                }
                ToastUtil.show(getContext(), "复制文本成功");
                return false;
            }
        });

    }
}
